<template>
  <div>
    <el-tabs type="border-card" style="margin-top: 30px;">
      <el-tab-pane label="新增医院设置页面">
        <!--新增界面-->
        <el-form :model="addForm" label-width="120px" :rules="addFormRules" ref="addForm">
          <el-form-item label="医院名称" prop="hosname">
            <el-input v-model="addForm.hosname" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="医院编号" prop="hoscode">
            <el-input v-model="addForm.hoscode" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="api基础路径" prop="apiUrl">
            <el-input v-model="addForm.apiUrl" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="联系人姓名" prop="contactsName">
            <el-input v-model="addForm.contactsName" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="联系人号码" prop="contactsPhone">
            <el-input v-model="addForm.contactsPhone" auto-complete="off"></el-input>
          </el-form-item>
        </el-form>
        <!-- 提交按钮 -->
        <el-button type="primary" @click="addSubmit" :loading="addLoading">提交</el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import apiObj from '../../api/hospSet/add'

export default {
  data () {
    return {
      addLoading: false,
      addFormRules: {
        hosname: [
          { required: true, message: '请输入医院名称', trigger: 'blur' }
        ],
        hoscode: [
          { required: true, message: '请输入医院编号', trigger: 'blur' }
        ],
        apiUrl: [
          { required: true, message: '请输入api基础路径', trigger: 'blur' }
        ],
        contactsName: [
          { required: true, message: '请输入联系人姓名', trigger: 'blur' }
        ],
        contactsPhone: [
          { required: true, message: '请输入联系人号码', trigger: 'blur' }
        ],
      },
      //新增界面数据
      addForm: {}
    }
  },
  methods: {
    //新增
    addSubmit () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true
            let para = Object.assign({}, this.addForm)
            apiObj.addHospitalSet(para).then((res) => {
              this.addLoading = false
              this.$message({
                message: '提交成功',
                type: 'success'
              })
              this.$router.push({ path: '/hospSet/list' })
            }).catch((e) => {
              this.$message.error("提交失败，请稍后重试")
            })
          })
        }
      })
    },
  }
}
</script>